package com.gg.utils;

import org.springframework.core.io.ClassPathResource;

import java.io.InputStream;
import java.security.PrivateKey;
import java.security.PublicKey;

/**
 * @Auther: YDYX
 * @Date: 2022/1/11 - 01 - 11 - 17:46
 * @Description: com.gg.utils
 * @version: 1.0
 */
public class PathUtil {
    /*
        获取私人秘钥
     */
    public static PrivateKey getPri() throws Exception {
        // String name = ResourceUtils.getFile("classpath:key/rsa.pri").getPath();
        // PrivateKey privateKey = RsaUtils.getPrivateKey(name);
        InputStream inputStream = new ClassPathResource("key/rsa.pri").getInputStream();
        PrivateKey privateKey = RsaUtils.getPrivateKey(inputStream);
        return  privateKey;
    }

    /*
        获取公共秘钥
     */
    public static PublicKey getPub() throws Exception {
        //String name = ResourceUtils.getFile("classpath:key/rsa.pub").getPath();
        //PublicKey publicKey = RsaUtils.getPublicKey(name);
        InputStream inputStream = new ClassPathResource("key/rsa.pub").getInputStream();
        PublicKey publicKey = RsaUtils.getPublicKey(inputStream);
        return  publicKey;
    }
}
